package com.audaque.encoding.mapper;

import com.audaque.encoding.dto.AnalysisInfo;
import com.audaque.encoding.dto.TableFieldInfo;
import com.audaque.encoding.dto.ValueInfo;
import com.baomidou.dynamic.datasource.annotation.DS;
import org.apache.ibatis.annotations.Param;

import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * @author mayong
 * @since 2024/7/1
 */
@DS("pg")
public interface PostgreSQLCommonMapper {
    /**
     * 获取表的字段定义
     *
     * @param tableName 表名
     * @return 定义列表
     */
    List<TableFieldInfo> getTableFieldInfo(@Param(value = "schema") String schema,
                                           @Param(value = "tableName") String tableName);

    String hasKeyField(@Param(value = "tableName") String tableName,
                       @Param(value = "schema") String schema,
                       @Param(value = "key") String key);

    int hasMustFields(@Param(value = "tableName") String tableName,
                      @Param(value = "schema") String schema,
                      @Param(value = "keys") List<String> keys);

    void createField(@Param(value = "tableName") String tableName,
                     @Param(value = "schema") String schema,
                     @Param(value = "keyField") String key);


    List<LinkedHashMap<String,String>> getData(@Param(value = "fields") LinkedList<String> fields,
                                @Param(value = "tableName") String tableName,
                                @Param(value = "key") String key);

    void updateDate(@Param(value = "info") AnalysisInfo analysisInfo,
                    @Param(value = "list") List<ValueInfo> cached);
    @DS("target")
    void insertData(@Param(value = "tableName") String tableName,
                    @Param(value = "schema") String schema,
                    @Param(value = "header") List<String> header,
                    @Param(value = "data") List<List<String>> data);

    @DS("target2")
    void insertData2(@Param(value = "tableName") String tableName,
                    @Param(value = "schema") String schema,
                    @Param(value = "header") List<String> header,
                    @Param(value = "data") List<List<String>> data);
}
